<?php
include("inc/head.php");

$GID = $_GET['GID'];

$Global = new Object();
if($GID)
{
$Global->getObjById($GID, "GID", "Global");
}
if($_POST['doPost'] == "true")
{
	$Global = new Object($_POST);
	if(is_numeric($GID))
	{
		$Global->MendTime = time();
		$Global->MenderID = $currAdmin->AID;
		$req = $Global->update('Global','Title,Content,Order,MendTime,MenderID','GID');
	}
	else
	{
		$Global->CreateTime = time();
		$Global->CreatorID = $currAdmin->AID;
		$req = $Global->add('Global','Title,Content,Order,CreateTime,creatorID','GID');
	}
		
	if($req)
	{
		new ActionLog(array("LogType"=>"global_sucess","Action"=>"$GID,$req\t{$currAdmin->AID}"));
		alert("sucess","location","globalList.php?GID=$GID");
	}
	else
	{
		new ActionLog(array("LogType"=>"global_err","Action"=>"$GID,$req\t{$currAdmin->AID}"));
		alert("err","location","globalList.php?GID=$GID");
	}
	exit;
}
?>
<form method="post">
<input type="hidden" value="true" name="doPost">
<input type="hidden" value="<?php echo $GID; ?>" name="GID">

<table width="90%" cellpadding="1" cellspacing="1" class="list-div">
	<tr>
		<th colspan="2" align="left" style="padding:0 0 0 10px;"> <?=$GID > 0 ? "修改":"新建"?>全局变量 <span><a href="?">新建</a></span></th>   
    </tr>
	<tr>
		<td width="100">名称</td>
		<td><input name="Title" type="text" value="<?=$Global->Title?>" /></td>
	</tr>
	<tr>
		<td width="100">序号</td>
		<td><input name="Order" type="text" value="<?=$Global->Order?>" /></td>
	</tr>

	<tr>
		<td width="100">内容</td>
		<td><textarea name="Content" cols="80" rows="20"><?php echo htmlspecialchars($Global->Content); ?></textarea></td>
	</tr>
	<tr>
		<td width="100"></td>
		<td><input type="submit" name="sub" value="提交"> <input type="button" onclick="history.go(-1)" value="返回" /></td>
	</tr>
</table>

</form>
<table width="90%" cellpadding="1" cellspacing="1" class="list-div">
	<!--tr>
		<th colspan="3" align="left" style="padding:0 0 0 10px;"> 新建/修改文档 <input type='button' value='返回' onclick='history.go(-1)' /></th>   
    </tr-->
	<tr>
		<td width="100">编号</td>
		<td>标题</td>
		<td>序号</td>
	</tr>
<?php
$sql = "select * from Global order by `Order` desc";
$result = $db->query($sql);
while($row = $db->fetch_array($result))
{
	?>
	<tr>
		<td width="100"><a href="?GID=<?=$row['GID']?>"><?=$row['GID']?></a></td>
		<td><a href="?GID=<?=$row['GID']?>"><?=$row['Title']?></a></td>
		<td><?=$row['Order']?></td>
	</tr>
	<?php
}
?>
<?php
include("inc/foot.php");
?>
